$(document).ajaxStart(function(){
	parent.$.messager.progress({
		title : '提示',
		text : '数据处理中，请稍后....'
	});
}).ajaxStop(function(){
	parent.$.messager.progress('close');
});

function isJson(obj){
	var isjson = typeof(obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() == "[object object]" && !obj.length;    
	return isjson;
}

function dealResult(json,callback){
	if(json&&isJson(json)&&json.STATUS&&json.STATUS=="300"){
		parent.$.messager.alert("错误",json.msg,"error");
		return false;
	}
	return true;
}

function ajaxError(xhr, ajaxOptions, thrownError){
	parent.$.messager.alert("错误","Http status: " + xhr.status + " " + xhr.statusText + "\brajaxOptions: " + ajaxOptions + "\brthrownError:"+thrownError + "\br" +xhr.responseText,"error");
}

function goAjax(options){
	var opts = $.extend({type:"post",dataType:"json",cache:false,async:true,traditional:false},options);
	$.ajax({
		type:opts.type,
		url:opts.url,
		async:opts.async,
		data:opts.data,
		dataType:opts.dataType,
		cache: opts.cache,
		traditional:opts.traditional,
		success: function(json){
			if(dealResult(json)){
				if($.isFunction(opts.callback)){
					opts.callback(json);
				}
			}
		},
		error: ajaxError
	});
}

function getWidth(percent){
    return document.body.clientWidth*percent; 
}

function getHeight(percent){ 
    return document.body.clientHeight*percent; 
}

/////////////fix jquery 
(function (original) {
	  jQuery.fn.clone = function () {
	    var result           = original.apply(this, arguments),
	        my_textareas     = this.find('textarea').add(this.filter('textarea')),
	        result_textareas = result.find('textarea').add(result.filter('textarea')),
	        my_selects       = this.find('select').add(this.filter('select')),
	        result_selects   = result.find('select').add(result.filter('select'));

	    for (var i = 0, l = my_textareas.length; i < l; ++i) $(result_textareas[i]).val($(my_textareas[i]).val());
	    for (var i = 0, l = my_selects.length;   i < l; ++i) {
	      for (var j = 0, m = my_selects[i].options.length; j < m; ++j) {
	        if (my_selects[i].options[j].selected === true) {
	          result_selects[i].options[j].selected = true;
	        }
	      }
	    }
	    return result;
	  };
	}) (jQuery.fn.clone);

